package resposta;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import beans.Cookie;

public class CabecalhoResposta {
	private String protocolo = "HTTP";
	private String versaoProtocolo = "1.1";
	private String codigo = "200 OK";
	private long contentLength;
	private String contentType;
	private String charSet = "UTF-8";
	private Map<String, String> atributos = new HashMap<String, String>();
	
	public CabecalhoResposta(long contentLength, String contentType){
		this.contentLength = contentLength;
		this.contentType = contentType;
	}	
	public String getVersaoProtocolo() {
		return versaoProtocolo;
	}
	public void setVersaoProtocolo(String versaoProtocolo) {
		this.versaoProtocolo = versaoProtocolo;
	}
	public String getProtocolo() {
		return protocolo;
	}
	public void setProtocolo(String protocolo) {
		this.protocolo = protocolo;
	}
	public String getCodigo() {
		return codigo;
	}
	public void setCodigo(String codigo) {
		this.codigo = codigo;
	}
	public long getContentLength() {
		return contentLength;
	}
	public void setContentLength(long contentLength) {
		this.contentLength = contentLength;
	}
	public String getContentType() {
		return contentType;
	}
	public void setContentType(String contentType) {
		this.contentType = contentType;
	}	
//	public void addCookie(Cookie cookie){
//		String valor = cookie.getChave()+"=deleted; expires="+cookie.getDataExpiracaoFormatada();
//		addAtributo("Cookie", valor);
//	}
	
	@Override
	public String toString() {
		String cabecalho = "";
		cabecalho = cabecalho+protocolo+"/"+versaoProtocolo+" "+codigo+"\n";
		cabecalho = cabecalho+"Content-Type: "+contentType+"; charset="+charSet+"\n";
		cabecalho = cabecalho+"Content-Length: "+contentLength+"\n";	
		Set<String> chaves =  atributos.keySet();
		for (String chave : chaves) {
			cabecalho = cabecalho+chave+":"+atributos.get(chave)+"\n";
		}
		return cabecalho;
	}
	public void addAtributo(String chave, String valor){
		atributos.put(chave, valor);
	}	
}
